package com.edu.chapter06;

import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class GameHolder extends RecyclerView.ViewHolder {
    public TextView tv_hello;
    private Button button;

    //    public GameHolder(@NonNull View itemView) {
//        super(itemView);
//        tv_hello = itemView.findViewById(R.id.tv_hello);
//        button = itemView.findViewById(R.id.btn);
//        button.setOnClickListener(v -> {
//            TextView textView = itemView.findViewById(R.id.tv_text);
//            textView.setText(tv_hello.getText());
//        });
//    }
    public GameHolder(@NonNull View itemView, GameAdapter.OnItemDeleteListener deleteListener) {
        super(itemView);
        tv_hello = itemView.findViewById(R.id.tv_hello);
        button = itemView.findViewById(R.id.btn);

        button.setOnClickListener(v -> {
            int position = getAdapterPosition();  // 动态获取当前位置
            if (position != RecyclerView.NO_POSITION) {
                // 通过回调触发删除
                deleteListener.onDelete(position);
            }
        });
    }
}
